<template>

    <div class="container">
        <div class="all-container">

            <!--信息栏-->
            <!--<el-row class="msg1-container">-->
            <!--<el-col :span="24">-->
            <!--<el-row>-->
            <!--<el-col :span="12" class="sell-form-container">-->
            <!--<FormData :ob="stronMsg" :op="stronOption"></FormData>-->
            <!--</el-col>-->
            <!--</el-row>-->
            <!--</el-col>-->
            <!--</el-row>-->
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
                <el-form-item label="票源">
                    <el-select v-model="formInline.region" placeholder="票源">
                        <el-option v-for="(item,index) in formInline.formData"
                                   :key="index"
                                   :label="item.name"
                                   :value="item.code">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>

            <!-- 表单数据栏 -->
            <el-container style="height: 800px; border: 1px solid #eee">
                <el-container>
                    <el-main>
                        <el-table :data="tableData">
                            <el-table-column prop="code" label="机构编码" width="140">
                            </el-table-column>
                            <el-table-column prop="name" label="简称" width="120">
                            </el-table-column>
                            <el-table-column prop="auth_start_date" label="起始日期">
                            </el-table-column>
                            <el-table-column prop="auth_end_date" label="截至日期">
                            </el-table-column>
                            <el-table-column label="授权">
                                <template slot-scope="scope">
                                    <el-switch v-model="scope.row.is_auth" :active-value="true"
                                               @change="switchChange(scope.row.id,scope.row.is_auth)"
                                               active-color="#009688" inactive-color="#CFCFCF"
                                               class="rf"></el-switch>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-main>
                </el-container>
            </el-container>

        </div>

    </div>
</template>

<script>
    import qs from "qs";

    export default {

        data() {

            return {

                formInline: {
                    region: "",
                    formData: [],
                },


                //表单数据
                tableData: [],
                value: '',

            };
        },
        methods: {
            switchChange(id, is_auth) {
                this.$http.get("/distribution/org/update", {
                        params: {
                            'distributionOrg.id': id,
                            'distributionOrg.is_auth': is_auth,

                        }
                    }
                )
                    .then(data => {
                        console.log(data);
                        this.$message({
                            message: data.data[1],
                            type: 'success'
                        });

                    });
            },
            //select框
            selectData() {
                var arr = [];
                this.$http
                    .get("/sys/org/tree"
                    )
                    .then(res => {
                        // console.log(res.data);
                        for (var c of res.data)
                            arr.push({
                                label: c.name,
                                value: c.code,
                            });

                        this.formInline.formData = res.data;
                        this.formInline.region = res.data[0].name;
                    });


            },


            impowerlist() {
                var arr = this.tableData = [];
                this.$http
                    .post("/distribution/org/list", qs.stringify({
                            filterRules: '[{"field":"dist_org.owner_org","op":"eq","value":265}]',
                            page: 1, rows: 30, sort: 'sys_org.no',
                            order: 'asc'
                        })
                    )
                    .then(res => {
                        for (var a of res.data.list) {
                            arr.push({
                                id: a.id,
                                code: a.no,
                                name: a.name,
                                auth_start_date: a.auth_start_date,
                                auth_end_date: a.auth_end_date,
                                is_auth: a.is_auth,

                            });
                        }
                    });

            }
        },
        mounted() {
            this.selectData();
            this.impowerlist();
        },

    }
</script>

<style scoped>
    .sell-form-container {
        height: 30px;
    }
</style>
